<template>
  <div class="container">
    <h1 style="text-align: center">导入导出</h1>
    <div style="margin-bottom: 100px">
      <h3>导入</h3>
      <input
        type="file"
        name="file"
        multiple="multiple"
        accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
        ref="file"
      />
      <el-button @click="handle">导入</el-button>
    </div>
    <!--  导出 -->
    <div>
      <h3>导出</h3>
      <el-button type="primary">导出</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ImportAndExport',
  data () {
    return {
    }
  },
  computed: {
  },
  methods: {
    /**
    1、accept
只能选择png和gif图片

<input id="fileId1" type="file" accept="image/png,image/gif" name="file" />
2、multiple
多文件上传

<input id="fileId2" type="file" multiple="multiple" name="file" />
3、常用MIME类型
后缀名       MIME名称
*.3gpp    audio/3gpp, video/3gpp
*.ac3    audio/ac3
*.asf       allpication/vnd.ms-asf
*.au           audio/basic
*.css           text/css
*.csv           text/csv
*.doc    application/msword
*.dot    application/msword
*.dtd    application/xml-dtd
*.dwg    image/vnd.dwg
*.dxf      image/vnd.dxf
*.gif            image/gif
*.htm    text/html
*.html    text/html
*.jp2            image/jp2
*.jpe       image/jpeg
*.jpeg    image/jpeg
*.jpg          image/jpeg
*.js       text/javascript, application/javascript
*.json    application/json
*.mp2    audio/mpeg, video/mpeg
*.mp3    audio/mpeg
*.mp4    audio/mp4, video/mp4
*.mpeg    video/mpeg
*.mpg    video/mpeg
*.mpp    application/vnd.ms-project
*.ogg    application/ogg, audio/ogg
*.pdf    application/pdf
*.png    image/png
*.pot    application/vnd.ms-powerpoint
*.pps    application/vnd.ms-powerpoint
*.ppt    application/vnd.ms-powerpoint
*.rtf            application/rtf, text/rtf
*.svf           image/vnd.svf
*.tif         image/tiff
*.tiff       image/tiff
*.txt           text/plain
*.wdb    application/vnd.ms-works
*.wps    application/vnd.ms-works
*.xhtml    application/xhtml+xml
*.xlc      application/vnd.ms-excel
*.xlm    application/vnd.ms-excel
*.xls           application/vnd.ms-excel
*.xlt      application/vnd.ms-excel
*.xlw      application/vnd.ms-excel
*.xml    text/xml, application/xml
*.zip            aplication/zip
*.xlsx     application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
*/
    /*
     FormData 对象的使用：
        1.用一些键值对来模拟一系列表单控件：即把form中所有表单元素的name与value组装成一个queryString
        2. 异步上传二进制文件
    */
    handle () {
      let file = this.$refs.file.files // 获取文件
      console.log('file: ', file)
      let data = new FormData()
      data.append('file', file.file) // 看那边接受的是键是什么 可能是img等
      // upload(data).then(res => console.log(res))

      // // 获得上传文件DOM对象
      // var oFiles = document.querySelector("#fileId");

      // // 实例化一个表单数据对象
      // var formData = new FormData();

      // // 遍历图片文件列表，插入到表单数据中
      // for (var i = 0, file; file = oFiles[i]; i++) {
      //   // 文件名称，文件对象
      //   formData.append(file.name, file);
      // }
    }
  }
}
</script>

<style scoped>
</style>
